﻿using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using HawaiRestaurant.Models.DataContext;

namespace HawaiRestaurant.Models.Repositories
{
    public class HawaiiRestaurantRepository : IHawaiiRestaurantRepository
    {
        #region Private Field
        private readonly DbDataContext _dataContext = new DbDataContext();
        #endregion

        #region Management Position

        public IEnumerable<Position> FetchAllPosition()
        {
            return _dataContext.Positions.ToList();
        }

        public Position GetPosition(int positionId)
        {
            return _dataContext.Positions.SingleOrDefault(a => a.PositionId == positionId);
        }

        public void AddPosition(Position position)
        {
            _dataContext.Positions.InsertOnSubmit(position);
        }

        public void DeletePosition(Position position)
        {
            _dataContext.Positions.DeleteOnSubmit(position);
        }

        #endregion

        #region Management FoodType

        public IEnumerable<FoodType> FetchAllFoodType()
        {
            return _dataContext.FoodTypes.ToList();
        }

        public FoodType GetFoodType(int foodTypeId)
        {
            return _dataContext.FoodTypes.SingleOrDefault(a => a.FoodTypeId == foodTypeId);
        }

        public void AddFoodType(FoodType foodType)
        {
            _dataContext.FoodTypes.InsertOnSubmit(foodType);
        }

        public void DeleteFoodType(FoodType foodType)
        {
            _dataContext.FoodTypes.DeleteOnSubmit(foodType);
        }

        #endregion

        #region Management DrinkType

        public IEnumerable<DrinkType> FetchAllDrinkType()
        {
            return _dataContext.DrinkTypes.ToList();
        }

        public DrinkType GetDrinkType(int drinkTypeId)
        {
            return _dataContext.DrinkTypes.SingleOrDefault(a => a.DrinkTypeId == drinkTypeId);
        }

        public void AddDrinkType(DrinkType drinkType)
        {
            _dataContext.DrinkTypes.InsertOnSubmit(drinkType);
        }

        public void DeleteDrinkType(DrinkType drinkType)
        {
            _dataContext.DrinkTypes.DeleteOnSubmit(drinkType);
        }

        #endregion

        #region Management Drink

        public IEnumerable<Drink> FetchAllDrink()
        {
            return _dataContext.Drinks.Include(a => a.DrinkType).ToList();
        }

        public Drink GetDrink(int drinkId)
        {
            return _dataContext.Drinks.SingleOrDefault(a => a.DrinkId == drinkId);
        }

        public void AddDrink(Drink drink)
        {
            _dataContext.Drinks.InsertOnSubmit(drink);
        }

        public void DeleteDrink(Drink drink)
        {
            _dataContext.Drinks.DeleteOnSubmit(drink);
        }

        #endregion

        #region Management Food

        public IEnumerable<Food> FetchAllFood()
        {
            return _dataContext.Foods.Include(a => a.FoodType).ToList();
        }

        public Food GetFood(int foodId)
        {
            return _dataContext.Foods.SingleOrDefault(a => a.FoodId == foodId);
        }

        public void AddFood(Food food)
        {
            _dataContext.Foods.InsertOnSubmit(food);
        }

        public void DeleteFood(Food food)
        {
            _dataContext.Foods.DeleteOnSubmit(food);
        }

       

        #endregion

        #region IHawaiiRestaurantRepository Members

        public void Save()
        {
            _dataContext.SubmitChanges();
        }

        #endregion

        #region Manager Staff
        public IEnumerable<Staff> FetchAllStaff()
        {
            return _dataContext.Staffs.Include(a => a.User).ToList();
        }

        public Staff GetStaff(int staffid)
        {
            return _dataContext.Staffs.SingleOrDefault(a => a.StaffId == staffid);
        }

        public void AddStaff(Staff staff)
        {
            _dataContext.Staffs.InsertOnSubmit(staff);
        }

        public void DeleteStaff(Staff staff)
        {
            _dataContext.Staffs.DeleteOnSubmit(staff);
        }

        #endregion

        #region Manager User
        public void AddUser(User user)
        {
            _dataContext.Users.InsertOnSubmit(user);
        }

        public void DeleteUser(User user)
        {
            _dataContext.Users.DeleteOnSubmit(user);
        }
        #endregion

        #region Manager Customer
        public IEnumerable<Customer> FetchAllCustomer()
        {
            return _dataContext.Customers.Include(a => a.User).Include(a => a.Position).ToList();
        }

        public Customer GetCustomer(int customerid)
        {
            return _dataContext.Customers.Include(a => a.User).Include(a => a.Position).SingleOrDefault(a => a.CustomerId == customerid);
        }

        public void AddCustomer(Customer customer)
        {
            _dataContext.Customers.InsertOnSubmit(customer);
        }

        public void DeleteCustomer(Customer customer)
        {
            _dataContext.Customers.DeleteOnSubmit(customer);
        }
        #endregion
    }
}